$.fn.extend({
	pageLoad: function(targetDom) {
		pageLoad.run(this, targetDom)
	}
});

var pageLoad = {
	run: function(self, targetDom) {
		this.$targetDom = targetDom ? $(targetDom) : $("#container")
		this.$self = $(self);

		this.htmlUrl = this.$self.data("html");
		this.apiUrl = this.$self.data("src");

		var that = this

		$.when(
			this.getHtml(),
			this.getData()
		).done(function(html, data) {
			_html = html[0]
			_data = data[0]

			laytpl(_html).render(_data, function(render){
			  that.$targetDom.html(render);
			});
		})
	},

	getHtml: function() {
		return $.ajax({
			url: this.htmlUrl,
			type: "GET",
			dataType: "html"
		})
	},

	getData: function() {
		return $.ajax({
			url: this.apiUrl,
			type: "GET",
			dataType: "json"
		})
	}
}

